Apparatus and Method for Processing Complex Instruction Formats in a Multi-Threaded Architecture Supporting Various Context Switch Modes and Virtualization Schemes

ABSTRACT

A unified architecture for dynamic generation, execution, synchronization and parallelization of complex instructions formats includes a virtual register file, register cache and register file hierarchy. A self-generating and synchronizing dynamic and static threading architecture provides efficient context switching.

BRIEF DESCRIPTION OF THE INVENTION

This invention relates generally to digital circuitry. More particularly, this invention relates to improved processor designs.

BACKGROUND OF THE INVENTION

Processors are required to handle multiple tasks that are either dependent or totally independent. The internal state of such processors usually consists of registers that might hold different values at each particular instant of program execution. At each instant of program execution, the internal state image is called the architecture state of the processor.

When code execution is switched to run another function (e.g., another thread, process or program), then the state of the machine/processor has to be saved so that the new function can utilize the internal registers to build its new state. Once the new function is terminated then its state can be discarded and the state of the previous context will be restored and execution resumes. Such a switch process is called a context switch and usually includes 10's or hundreds of cycles especially with modern architectures that employ large number of registers (e.g., 64, 128, 256) and/or out of order execution.

In thread-aware hardware architectures, it is normal for the hardware to support multiple context states for a limited number of hardware-supported threads. In this case, the hardware duplicates all architecture state elements for each supported thread. This eliminates the need for context switch when executing a new thread. However, this still has multiple draw backs, namely the area, power and complexity of duplicating all architecture state elements (i.e., registers) for each additional thread supported in hardware. In addition, if the number of software threads exceeds the number of explicitly supported hardware threads, then the context switch must still be performed. This becomes common as parallelism is needed on a fine granularity basis requiring a large number of threads. The hardware thread-aware architectures with duplicate context-state hardware storage do not help non-threaded software code and only reduces the number of context switches for software that is threaded. However, those threads are usually constructed for coarse grain parallelism, and result in heavy Software overhead for initiating and synchronizing, leaving fine grain parallelism, such as function calls and loops parallel execution, without efficient threading initiations/auto generation. Such described overheads are accompanied with the difficulty of auto parallelization of such codes using sate of the art compiler or user parallelization techniques for non-explicitly/easily parallelized/threaded software codes.

SUMMARY OF THE INVENTION

A unified architecture for dynamic generation, execution, synchronization and parallelization of complex instructions formats includes a virtual register file, register cache and register file hierarchy. A self-generating and synchronizing dynamic and static threading architecture provides efficient context switching.

BRIEF DESCRIPTION OF THE FIGURES

The invention is more fully appreciated in connection with the following detailed description taken in conjunction with the accompanying drawings, in which:

FIG. 1 illustrates instant saving and restoration of register state using direct connectivity to a register file.

FIG. 2 illustrates a virtual register file with a register location map in accordance with an embodiment of the invention.

FIG. 3 illustrates a multiple hierarchy register file with temporary storage for speculative register state in accordance with an embodiment of the invention.

FIG. 4 illustrates a register cache for virtualizing software contexts/threads in accordance with an embodiment of the invention.

FIG. 5 illustrates a register cache with an automatic mechanism to spill and reload registers upon a context switch in accordance with an embodiment of the invention.

FIG. 6 illustrates the resolution of false dependencies on register names using a counter scheme in accordance with an embodiment of the invention.

FIG. 7 illustrates a known super scalar execution architecture.

FIG. 8A illustrates an execution architecture utilized in accordance with an embodiment of the invention.

FIG. 8B illustrates a buffer, scheduler and reorder unit that stores inheritance information in accordance with an embodiment of the invention.

FIG. 9A illustrates a global front end and inheritance vector to enforce sequential consistency among threads across a group of cores in accordance with an embodiment of the invention.

FIG. 9B illustrates register interconnect topology to allow inter-thread and intra-thread register communication across cores in accordance with an embodiment of the invention.

FIG. 9C illustrates a location based register referencing across a physically segmented architecturally unified register file in accordance with an embodiment of the invention.

FIG. 10 illustrates a mechanism to automatically generate threads that span loop iterations and boundaries in accordance with an embodiment of the invention.

FIG. 11A illustrates mechanism to automatically generate threads that span across control paths in accordance with an embodiment of the invention.

FIG. 11B illustrates test and branch instruction processing in accordance with an embodiment of the invention.

FIG. 12 illustrates a segmented/distributed cache with separate tag and data arrays utilized in accordance with an embodiment of the invention.

FIG. 13A illustrates a mapping mechanism to enable precise scheduling between a pre-fetch instruction and its load consuming instruction.

FIG. 13B illustrates dynamic allocation of temps and chains to physical storage by virtualizing hardware storage in accordance with an embodiment of the invention.

FIG. 14 illustrates a counter mechanism in a scheduler vector to enable renaming of address registers without the need for extra physical registers, as utilized in accordance with an embodiment of the invention.

FIG. 15 illustrates a bypass and check mechanism implemented in accordance with an embodiment of the invention.

Like reference numerals refer to corresponding parts throughout the several views of the drawings.

DETAILED DESCRIPTION OF THE INVENTION

One aspect of the invention reduces context switch penalty. A context switch penalty occurs because of the time it takes to save the architecture state (e.g., data registers, control registers, program counters, etc.) The state of the previous context has to be restored before resuming execution. This means that many loads/stores of a large number of registers need to occur for something as common as an involved function call. Disclosed is an architecture state structure to do a gradual self context-switch as well as an instant context switch on the architecture state. Also, the concepts of a virtual register file and a register cache are introduced as possible implementation components. The virtual register file or register cache also provide support for virtually larger number of threads or contexts in the hardware than possible using traditional hardware thread support. A multi hierarchal register file support provides larger bandwidth to the register file.

The techniques can also be combined with threading support. One part of the architecture state will undergo an instant hardware/software supported context switch where all the architecture state is saved quickly/instantly by the hardware using a LIFO (Last-In First-Out) circuit. The use of a LIFO circuit allows for lower complexity and efficient speed and area implementations, as opposed to register file or random access memory implementations. Each subsequent context switch that belongs to this category is saved on top of the old context in the LIFO. This technique is well suited for recursive functions calls or nested parallelized loops where the context of one call in the recursion will naturally be entered and exited in a LIFO manner. FIG. 1 illustrates one embodiment of hardware context-switch support.

Another way of doing this quick saving of the architecture state is to save the register file content as one block in memory or cache (e.g., one cache line or block). A register batch is a series of subsequent register numbers (e.g., registers 0 to 7 might be a subset of a larger register set 0-64) that can be stored as a one cache line of size 64 bytes when a context switch involving those 8 registers occurs. The register file has dedicated wide buses 101 and 102 that directly carry all of its content either in the same cycle or in a small number of cycles, as opposed to typical usage of loads and stores to save and restore each individual register. One possible implementation of the register file to cache transfer is to use the buses 102 and 101 to connect to the fill buffers that are commonly used to fill cache lines as a back door path to move registers directly to cache. One alternative implementation can use write/read combining buffers that are typically used to accumulate partial stores and loads data into a buffer before writing them on the bus to the memory as a single transaction, instead of each forming a partial bus transaction. Such a combining buffer can have a side door bus connection through 101 and 102 to combine the series of registers into one write combining buffer that can then transfer the whole cache line worth of registers into the cache or memory while it can use the read combining buffer to do the opposite transfer. The use of a specialized local memory with a LIFO circuit or random access memory buffer is also another implementation choice. The LIFO circuit is simpler and has less implementation constraints, but imposes a strict order of saving and restoring data (last in first out). On the other hand, a random access memory, such as using a direct bus to processor cache has the flexibility of using local memory, but imposes hardware implementation constraints, while allowing flexible saving and restoring of contexts in random order.

Another part of the architecture state may be saved and restored gradually as the new context is replacing the old context. In other words, the individual registers are swapped/read in and out by the hardware upon the use of that particular register in the new or old context. This gradual context switch is suitable for global variables and variables that are passed from one function to another through the context switch. It also fits those variables that are passed through nested loops if the loops are threaded, such that the inner loop is assigned to a different thread than the outer loop. It can also be applied to the cases where different iterations of the loop are assigned to different threads and these iterations pass several variables from one iteration to the other (loop carried dependency). In all those cases it is advantageous to perform a gradual context switch for the registers because the number of registers that are commonly used between threads (the registers that passes data between the contexts) is large, thus those registers can be shared and do not need to undergo a context switch, while the remaining registers can be swapped as needed gradually.

The invention may also utilize virtual registers to allow for the containment of a larger set of registers than those directly supported by the instruction set architecture. The extra registers are part of the hardware supported context switch or hardware/software threads. The concept of a register cache or register hierarchy is also applicable for such scenarios. A virtual register file is a register file architecture where the instruction set registers visible to the architecture are extended and are still visible using the virtual register file storage. This facilitates keeping multiple copies of the same architecture register that belong to different context switches or threads. This also enables larger or variable numbers of registers than those directly accessible using a traditional physical register file. Those copies of the architecture registers are visible to the hardware in the case the hardware is generating the threads/contexts (hardware-threads) and they can also be overloaded with software threads if the software is generating them (software-threads).

FIG. 2 shows one implementation of such a virtual register file by utilizing a hierarchy of the register file. Lower hierarchy levels 201 supports very high bandwidth to the execution units. Higher hierarchy 200 levels support lower bandwidth access. Some levels of the register file hierarchy contain the basic register set that is supported by the instruction set architecture, while other levels of the register file hierarchy contain virtual copies of the basic register set. It is also possible to allow the basic register set to be duplicated for multiple thread support.

It is also possible to include in this hierarchy a register cache where registers are cached in and out of this structure based on their relevancy to current context and their immediate access needs. One way to implement this virtual register file and register cache is by providing tags to the register locations such that they are accessed by the tags that include the actual register number in addition to other information, such as context ID number or static thread number and possibly the memory address where they should be saved for the context switch. Other alternative techniques are also described here in where an index map 202 uses position-based information about each of the architecture registers. The position (location) of the register copy in the hierarchy is looked up as part of the decoding phase of the register read access of the register file 203. Other mechanisms include passing the location of the register as part of the score board mechanism from the producer instruction of the register to its consumer instructions. Consumer instructions need to read the register so that they know which copy of that architecture register they need to access, but in the location/position based schemes, no tags are needed because the register is accessed by its register number and the location where the particular register copy is physically located among the multiple copies of that register in the multi-hierarchy register file.

The mechanism of gradual context switch can use similar mechanisms to current context switch of loading and storing the individual registers with the following differences. An individual register is hardware swapped/read when a new context attempts to use it and the local copy belongs to the old context. At that time the register belonging to the old context is swapped with the global register copy in 200 that belongs to the new context which is brought into the local register file 201. In one implementation, multiple registers that carry the same register number can coexist, but with different context ID tags. One implementation of the tag scheme can resemble a virtual register file where the same registers from different contexts are present. A virtual register file is interesting as it allows for a large virtual register file to be implemented as a hierarchy of multi level register-files with different bandwidth and capacity variations. The following example illustrates different scenarios where functions are presented. Assume that different function calls within a single program/task are called at subsequent times.

Function 1 (values, references) { a-d: local variables X-Z: global variables Code } Function 2 (values, references) { a-d: local variables X-Z: global Variables Code { Function 3 (values, references) a-d: local variables X-Z: global variables If (condition) then call Function 3( ) } Main { Function 1( ) .... Function 2( ) Function 3 ( ) .... } The old local variables in the Local register file as a whole need to be saved if the old context is not needed, it makes sense here to use instant saving for contexts, other cases where the whole context needs to be saved are when a new independent process is invoked by the operating system.

On the other hand, if not all of the registers of the old context need to be saved, then only those that need to be saved are gradually swapped with the new context register values. This is the case where function 1 and 2 coexist together in the same local register file and share the same global registers in the global register file. This is the case for fine grain threads. In such case, when a particular register in a certain context needs to be accessed, its context ID is checked with the one that exists in the local register file. If they match, then it can be used, else it needs to be brought/read from a higher storage hierarchy (such as the global register file or the register cache) and may be swapped with the one that is in the local hierarchy storage (e.g., the temporary local register)

At the call of the Function, the new variables that are to be written within the function scope are assigned to new register copies (with a new context/thread ID compared to the external scope of the function). Those new register name copies can be assigned either by a hardware management unit (HMU) or by a compiler/programmer that generates code for this architecture. In case of the HMU, the HMU unit upon entering the function code (the one between the call and return instructions) will assign a new context/thread ID number to each register name that is being written within the function scope, thus generating copies of the register names. Upon reaching the return instruction this context/thread ID becomes free for reassignment and all the register name copies can be reused again. There is no overhead in creating and synchronizing these temporary contexts because the hardware automatically manages the assigning and freeing of these temporary copies of register names.

The compiler can handle the management of the register names in different contexts if the instruction architecture allows for extending the register name with a context/thread ID number. This way the instructions that write into a specific register name will also specify the context/thread that the instruction writes to and reads from. Consider a typical instruction with 3 sources (S1, S2, S3) and one destination (Dest) as encoded below

Dest/S1←ADD (S2, S3)

In this example, the registers and their association to threads will be formatted as:

Th_(y):R_(x)←ADD (Th_(z):R_(i), Th_(w):R_(k))

This shows how the instruction architecture allows for specifying the context/thread ID i.e., “Th_(y) “where y being the thread ID” alongside register R_(x) with register name x. The compiler or the programmer can specify the context/thread number that the register names belong to. When a code for a function is compiled the compiler can increment the context/thread ID number using a special instruction to increment the thread ID counter; then this counter is decremented upon exiting the function call using a decrement instruction. Another mechanism that the instruction architecture can use is to implement a free thread selector instruction. The compiler/programmer uses this instruction to poll the hardware to find a free context/thread ID which it can use. Upon returning from the function it can uses another instruction such as a context/thread free instruction. The following illustrates these 2 methods:

Increment thread ID counter Function A: (( Th+:R_(y) ← Move Th:R_(y) ) { Function body } Return ( Th−:R_(i) ← Move Th:R_(i) ) Decrement thread ID counter

The reason for having the increment before the function call and the decrement after the return is to allow for passing the values between the caller and callee. The increment creates the new context/thread number and the decrement frees it.

An alternative method that does the same task uses an instruction that selects a free context/thread number and another instruction to free that context/thread number.

J =current Thread number I=Select free thread ID number Function A: ( Th{I}:R_(y) ← Move Th{J}:R_(y) ) { Function body } Return ( Th{J}:R_(x) ← Move Th:R_(x) ) Free thread ID number {I}

To reduce the encoding space for the context/thread number associated with each register name, the instruction architecture can specify that a register is associated with the parent thread or with the current child thread; this can be encoded with one bit (we will call the parent/child bit: “P/C” bit). Each new generated thread will specify its parent thread (the thread that it was spun out of). The parent ID number will be kept along with the other thread state. A hybrid scheme can be used where the instruction can specify one/more sources from the current child or parent thread using the parent/child bit and one/more sources from another non-related thread using an explicit thread number along with that source register name. The following instruction set architecture illustrates such hybrid scheme:

P/C:R_(x)←ADD (P/C:R_(i), P/C:R_(j), Th_(w):R_(k))

The “P/C” bit specifies if the register belongs to the parent thread or the child thread. This scheme can be generalized where more bits can be designated to encode active threads within a higher level context. The following illustrates this more general scheme. A high level context defines few threads within its state. Processor architecture allows for small size of stored states that the instruction set can abbreviate. Assuming that the processor hardware can support a total of N threads, the instruction set can support an abbreviation of those threads that allows intercommunication of M threads through the registers in the instruction set encodings, where M<N. This will allow for a larger number of threads to be supported by the instruction set architecture than the abbreviated encoding bits allows. For example, let us assume that the hardware can support 128 threads (N=128). One can define the instruction set encoding to have an encoding for only 4 threads (M=4), such that those threads' registers can be simultaneously accessed by 4 active threads out of the 128 threads. Those 4 threads can rotate among the 128 threads depending on the active region of the program. Few bits (T₁ . . . T_(log M)) can be used to encode M threads in the instruction. In this example 2 bits T₁T₂ are used to encode 4 threads.

T₁T₂:R_(x)←ADD (T₁T₂:R_(i), T₁T₂:R_(j), Th_(w):R_(k))

Mapping the active threads within a program region to the overall set of threads supported by the hardware can be done though mapping or assignment instructions as the following example shows

Map (T₁T₂=00), TH=0001101

Map (T₁T₂=01), TH=1001000

Map (T₁T₂=10), TH=1010101

Map (T₁T₂=11), TH=0111100

01:R_(x)←ADD (01:R_(i), 10:R_(j), 1000110:R_(k))

In the above example of code the instructions map the hardware threads to the abbreviated encoding represented by the 2 bits T₁T₂ of the mapping instructions. By way of example, the add instruction encodes only 2 abbreviated bits for the threads of each source and the destination. The third source, however, explicitly encodes the thread of its source. The decision of the number of bits to encode in the instruction set to abbreviate the threads is an implementation decision that can vary from one architecture to another, also including a third source or having its thread explicitly encoded is an implementation choice.

To implement the pipeline of a processor that executes such instructions or micro operations (microcode implementation of the instructions), this pipeline will store those maps and use them to access the correct thread state when it executes an instruction that encodes the abbreviated thread bits. Those mapping states can expand a register allocation algorithm for mapping single thread variables to registers, where the compiler can allocate a larger set of threads to the limited number of mapping states and then perform the register allocation within each thread. This way the mapping states can be reallocated for new threads through out the program using live ranges of threads similar to live ranges of registers.

Map ( T₁T₂= 00), TH = 0001101 Map ( T₁T₂= 01), TH = 1001000 Map ( T₁T₂= 10), TH = 1010101 Map ( T₁T₂= 11), TH = 0111100 01:R₅ ← ADD (01:R_(2,) 10:R₃,1000110:R₁₀) 01:R₈ ← MUL (01:R_(4,) 01:R₅,1000110:R₁₂) Map ( T₁T₂= 10), TH = 1011111 01:R₅ ← ADD (01:R_(2,) 10:R₃,1000110:R₁₀) 01:R₈ ← MUL (01:R_(4,) 01:R₅,1000110:R₁₂)

If the processor is an out of order processor, it can also allow for renaming of those abbreviation maps to allow for more of those active region threads to be executed simultaneously. For example, in such an out of order processor, the above code will be decoded to rename those abbreviated bits internally in the actual micro operation encodings to the full thread number. In such an out of order machine temporary speculative registers are also implemented to keep those renamed registers and states. FIG. 3 implements temporary registers where speculative state can live in temporary registers such as 301 before they are committed to the global register file.

The general scheme described enables fine grain threads to communicate, cooperate and synchronize execution on register level execution without the need to go through memory, while at the same time having the instruction set encodings very compact by providing register association to threads, while minimizing instruction encoding space. All the schemes described above require the compiler to insert instructions to manage the threads and set the extension bits, can be performed by a hardware management unit that executes similar actions to the instructions and manage the setting of those extension bits (as described throughout the invention).

We generalize the above mechanisms to handle fine grain threads beyond function calls, to include threads across loop boundaries and creating threads between the body of the loop and the code outside a loop body. Consider the following code:

Loop ( j= 1 to 100) { Instruction A Instruction B Loop (i=1 to j) { Instruction 1 Instruction 2 } Instruction C } Using the compiler or the hardware management unit, the thread that represents the inner loop body (instructions 1 and 2) and the thread that represents the instructions outside the inner loop body can be mapped into hardware supported threads.

The following implementation, by way of example, represents one scheme where those fine grain threads can be live in the register file/register cache and be swapped in and out into higher level register file hierarchies as well as memory hierarchies. The assumption is that a compiler will be designed to use some convention that saves context depending on the number of registers used in the called function. So it can save a number of registers in an incremental way. For example, if the design convention is to use register batches in increments of 8, then if a function needs to use a number of registers that is between 1 and 8 registers it will save registers 1 thru 8 of the old context (and will restore them when it restores the old context). If it needs to use a number of registers between 1 and 16 it will then save registers 1 to 16 and so on and so forth to the full extent of saving the whole registers supported by the architecture. One other scheme that allows for establishing a virtual register file is the aliasing of the registers of different contexts/threads that need a smaller number of registers than that provided by the instruction set architecture. For example, a small function call or a worker thread might only need to use a subset of all the registers e.g., 8 registers (register 0 to 7) out of the 32 registers available by the instruction set. If this is the case, then the hardware/compiler will alias this 8 logical register batch on top of another free physical register batch, the register batch that the thread gets mapped to does not need to be with the same register numbers; i.e., registers 0-7 can be mapped onto physical registers 8-15 or 16-23 or 24-31 that are available in another context physical state storage.

FIG. 4 shows such scenario. Thread 5 state 402 which is composed of registers 0-7 is aliased on top of a free context register batch 8-15. This means that more threads can be accommodated than the typical case where each thread is mapped onto the whole 32 register state. In FIG. 4, typically only 4 threads can coexist at the same time because there are only 4 sets of 32 registers that can be used simultaneously. However if most of the additional threads (beside the main thread which might need the 32 register large sate for itself) have small set register requirements and they can each live with 8 registers small state, then we can simultaneously process 13 threads in total. The maximum number of simultaneous threads that can coexist in this 8 register batch aliasing configuration is 16 small state threads. Obviously, we do not need to store a tag per register as shown in the figure for illustrative purposes. In efficient implementations you can store a thread tag per batch (8 registers in this example) or also alternatively threads can be allocated according to a number aliasing scheme where the thread number starts at boundaries of multiples of 8. For example, if we start allocating registers based on this scheme, FIG. 4 shows the software threads numbers 0, 1, 3, 4, 5, 6, 7 and 9. As described earlier, the software threads will be mapped to the physical hardware threads either by instruction set (thru the compiler) or by a hardware management unit. The aliasing scheme now allows 16 hardware threads to be mapped to the software threads. In this scenario software thread 0 reserves hardware threads 0, 1, 2, 3 because it needs the whole 32 registers large state and thus uses 4 batches of 8 register each. However, software thread 1 reserves only one small state hardware thread storage and thus is mapped on hardware thread 4. Software thread 5 is mapped onto hardware thread 5, software thread 3 is mapped on hardware thread 6 and software thread 6 is mapped on hardware thread 12 (shown in the figure as point 400).

In instruction set or microinstruction encoding, to allow the aliasing scheme described above, the reference to a thread-register pair can be a continuous encoding of bits, where the top 4 bits will be the hardware thread number (indicating which batch of 8 registers the thread references) and the lower 3 bits will indicate individual register in the register batch 0-7.

As an example, assume that the software needs to perform the following high level threaded task of adding certain registers in different threads and write the result in register 2 in software thread 1, shown as 403 in FIG. 4 as follows:

Th1:R₂←ADD (Th0:R₁₃, Th3:R2, Th6:R₃)

Then the mapping of the software threads to hardware threads will be done either by the compiler or the hardware management unit. Such mapping ensures that software threads which need more than 8 registers reserve more than just one hardware-thread storage, thus no other software thread can use those reserved hardware threads to map onto. The actual instruction encoding of the task will be written as follows, 0100010←ADD (0001101, 0110010, 1100011) which decodes to the following:

HWTh4:R₂←ADD (HWTh1:R₅, HWTh6:R₂, Th12:R₃)

Note that software thread 0 register 13 was encoded as hardware thread 1 (401) register 5 (0001 101, first 4 bits are hardware thread number and last 3 bits are register number) because the mapping of software thread was aliased on 4 small state hardware threads 0, 1, 2, 3 each of which has a batch of only 8 registers. Alternatively the same encoding can be read as hardware thread 0 register 13 (00 01101, the first 2 bits is the number of large state hardware thread (one with 32 register state) and the last 5 bits are the register number among the 32 registers)

Another scheme that can be implemented on top of previous register cache scheme is one that provides an automatic store load mechanism between this register cache and the memory cache to allow the register cache to spill out and reload registers automatically upon context switches and thread context swapping which is illustrated in

The following code illustrates the scheme and how the hardware described in FIG. 5 works to allow a seamless multithreading context switching. The register cache (built similarly to typical associative caches with sets and ways) has tow parts; the tag array and the data array. The data array is accessed similar to any threaded register array; a register read happens upon any instruction that accesses that thread register. However, the tag array is accessed upon any load or store instruction that is a part of a context switch, which is also known as saving and restoring the context. The tag part of the register cache is only updated with a current stack memory address for a particular register when the current thread context for that register is stored (saving the context) provided that there is no need to actually store the value to the memory because there is still empty ways in that particular register set in the register file cache. Later this tag is used to actually evict the register when there is no free ways in the register cache to store a new thread that needs to allocate the same register name. The following code illustrates this:

Main (thread 0) ... Thread 1 { Save register batch (0-7) starting address X_1 } { address X_1 ← store R0 , address (X_1 +4) ← R1 , ... , address( X_1 +28) ← R7 } ... Thread 4 { Save register batch (0-7) starting address X_4 } { address X_4 ← store R0 , address (X_4 +4) ← R1 , ... , address( X_4 +28) ← R7 } ... Thread 6 { Save register batch (0-7) starting address X_6 } { address X_6 ← store R0 , address (X_6 +4) ← R1 , ... , address( X_6 +28) ← R7 } ... Function foo (thread 8) { Save register batch (0-7) starting address X_8 } { address X_8 ← store R0 , address (X_8 +4) ← R1 , ... , address( X_8 +28) ← R7 }  R0 ← add ...  R1 ← move ... R3 ← subtract ... R2 ← add ... R5 ← move ... R5 ← subtract ... Restore register batch (0-8)  { R0 ← LD address X_8 , R1 ← Ld address (X_8 +4) , ... ,R7 ← LD address( X_8 +28) } Return

In the above code the compiler wants to save to the memory stack, registers R0 thru R7 of thread 0 that will be overwritten by threads 1, 4 and 6. In this scheme we allocate the memory region in the stack to accommodate register batch (0-7) but the hardware do not really perform the store of the registers of thread 0 to the memory/memory cache when threads 1, 4 and 6 are encountered. This is because the multi-context register file cache is able to provide storage 501 to the extra 8 registers (0-7) that those threads need without destroying registers 0-8 of the original thread (thread 0). As long as the multi-context register file cache can accommodate those registers, it only updates the tag array in the register cache with the stack memory address that the store instructions intended to perform. Notice that when thread 8 is encountered (“function foo”), because the ways of the register cache are all occupied for register batch 0-7 then the stores of registers 0-7 for thread 0 has to happen and in fact it is similar to the eviction process in a typical cache where the registers 0-7 of thread 0 are evicted to the real stack memory/cache hierarchy storage 500 while the register file cache thereafter, contains values for register 0-7 of thread 8 in the storage area 502.

The mechanism for context switch can also facilitate other techniques, such as the dynamic self generation and synchronization of threads. Concurrent execution of different parts of a single task or program currently requires the implementation of an out-of-order “Super scalar” processor architecture. However, out-of-order execution requires plenty of hardware investment and complexity. The following are typical implementation components that are needed for such concurrent execution using an out-of-order micro-architecture:

-   -   1—Allocation logic to allocate all resources in the sequential         order of the program.     -   2—Rename logic and register map to map logical registers to         physical registers at allocation and update the logical         registers at retirement of physical registers.     -   3—Reservation station to dispatch the operations out-of-order         according to availability of resources and after dynamically         resolving dependencies.     -   4—Reorder buffer to allow for reordering the results in the         initial sequential order before retiring them to the         architecture state. It also maintains precise exception         behavior.     -   5—A memory reorder buffer to reorder memory accesses that are         dispatched out of order to maintain the same consistency model         as if they are dispatched in order, for example, checking for         load after store to the same address. It is also necessary to         maintain the order of access for special memory accesses like         memory mapped I/O.         Few architectures have capitalized on the super scalar nature of         the out-of-order machines and their ability to dispatch multiple         independent streams of instructions to allow multiple software         threads to simultaneously execute in the machine. This         simultaneous multi-threading requires duplicating the         architecture state of the machine for each hardware         supported-thread and partitioning the micro architecture         resources between threads and sharing the memory structures like         caches between those threads.         Despite the fact that those machines are out-of-order, they do         not initiate, self dispatch, synchronize or enable concurrency         between threads by the out-of-order hardware itself. Rather, all         those tasks are left to the software, which initiates/generates         and dispatches the threads when their dispatch         condition/dependency is met (e.g. using barriers). The software         synchronizes them when there is common control or dependencies         between them (using locks for example). The software also         determines the concurrency between them. The software mentioned         earlier could be the actual master thread code or the compiler         that tries to statically parallelize non-threaded code. Usually         those threads are implemented using coarse-grain parallelism         leaving fine grain parallelism without efficient threading         initiations because of the difficulty of automatic         parallelization of such codes.

The following discussion illustrates that with a new paradigm of hardware/software, automatic parallelization is achieved even without using the elaborate out of order micro-architecture support. The new hardware generates, synchronizes, parallelizes and concurrently executes those fine/coarse grain static and dynamic threads by dynamically detecting that the control conditions and/or the dependencies are resolved and/or by allowing for the cross reference of registers between threads also by disambiguating memory references across those threads. This is done by having the hardware monitor either a control condition associated with triggering the thread or the write back of cross referenced register values on which the current thread depends on.

The initiation/generation of the thread dynamically by hardware is triggered when all its dependency registers and/or control conditions, particularly those of cross reference nature (e.g., inter-thread registers) are satisfied. This can be monitored through the explicit list of sources that this thread is dependent on. These hardware initiated dynamic threads can be thought of or actually can be things like a function call or a method or subroutine or even a loop instance that can be encapsulated in a form of a repeated function call. This function call has a parameter list on which its execution is dependent. Those parameter lists or registers are monitored for their write back stage occurrence. Once each parameter/register is written back after its updating instruction has executed, a flag is set. When all the flags of those parameters/registers are set, then the function/thread can be dynamically dispatched by the hardware. The allowance for cross referencing of the registers or virtual registers and/or memory references among the different threads (both the hardware generated as well as the software generated) establishes a way to generate, synchronize, parallelize and concurrently execute those threads using a natural dependency resolving method such as the one used to create consistent execution of programs using registers to communicate dependencies.

The lazy gradual context switch mentioned earlier also helps to allow the new state of those dynamically generated or software static threads to be built/swapped with other existing dynamic/static threads as illustrated earlier.

FIG. 6 shows one possible mechanism of resolving false dependency on the same-name registers during the dynamic execution of those threads. This can also maintain sequential order of register updates by augmenting the register number with a differentiating bit-field that is tagged at instruction allocation time in the machine. At the front end, each register has 2 counter values corresponding to this bit filed. One counter value (lead counter) 601 is incremented at each new assignment of that register as a destination to an instruction. Another pointer 602 (lag counter) is incremented at each commit of a corresponding register to the architecture state. The lag counter can never bypass the lead counter. The lead counter can wrap around to the initial value after reaching the maximum; the lag counter has the same functionality. Those counters can be extended to be thread-specific, such that each thread has its own counter.

The lead counter 601 for a specific register keeps incrementing as a new instant of the same register is being assigned as a destination to a new instruction. Each time a register is reassigned as a destination to new allocated instructions 603, this bit field of that register is incremented (in the front end of the machine) and attached to the hardware instructions 605. Each subsequent instruction using this register as a source 606 will use the new incremented register number extended field. Whenever that register commits to final architecture state, then that register bit field lag counter 602 at the front end is incremented. The reason to use and increment the lag counter is to determine if a particular register value needs to be read from the speculative reorder buffer or from the retired register file by comparing (at the instruction register read stage) the register extended field of the hardware instruction with the lag counter of that register from the lag counter pointer. The lag counter 602 gets incremented at retirement pipeline stage 604 This mechanism can also apply to individual instructions and not only to function's calls or threads.

The lead counter and lag counter table shown in FIG. 6 can be replaced with an inheritance vector that has a field for each of the architectural registers. At allocation time, this vector forwards the incremented values from each instruction to the next while each instruction increments the value in the bit field related to its destination register. A similar concept is shown in FIGS. 8.a/8.b but for a group of instructions as opposed to only one instruction.

In the following paragraph a preferred method is described to unify automatic/dynamic threading generation and synchronization along with the handling of context switches described earlier. In addition, the concept of physically-segmented architecturally-unified register file is disclosed with a register hierarchy that is well suited to such an implementation.

The architecture may also include an instruction matrix/block/bucket architecture (matrix, block or bucket are used exchangeably) where instructions are part of an “Ultra Large Instruction Matrix” referred to in a previous invention by the same inventor as “ULIM Architecture” in PCT/US2007/066536, which is incorporated herein by reference. The instruction matrix/bucket/block is a collection of instruction that might be totally dependent on each other or totally independent or something in between (some instructions depend on others while some are independent with respect to others). Usually the instruction matrix/block encapsulates instructions in a matrix format where dependent instructions must occupy a column within the matrix and independent instructions occupy rows or columns. The matrix dimensions (rows, columns) can be selected from few possible configurations that the architecture maps to its hardware execution units. The Matrix/Block/bucket architecture is a concept that allows the passing of dependencies on the level of an instruction block/Bucket identity instead of individual sources. Thus, the architecture efficiently removes complexities associated with CAM (content addressable Match) matching sources and destinations in a large scale concurrent instruction execution architecture. It is possible to design the disclosed inventions without the explicit use of the ULIM architecture or the even instruction buckets/blocks, by using instead a virtual identifier that serves a similar role to the bucket/block role such that it tracks and resolves dependencies on a source group level without really forming a matrix or block but by using grouping of simple instructions. This is an implementation advantage over the current schemes that use individual source dependency tracking and resolution per single instruction.

Within an instruction bucket and across the buckets, instructions can be assembled as VLIW or SIMD or MIMD. Then the buckets are dispatched and executed as dynamic threads. In addition, the static software threads can share the same mechanisms described for dynamic threads with the difference that they are generated based on the software application threads.

FIG. 7 illustrates a traditional super scalar out of order architecture as described in the related state of the art. Individual instructions are renamed using a rename table (not shown in the figure) that maps architecture registers into a pool of physical ones, then the instructions are scheduled, executed and retired. Shown in FIG. 7 is a typical instruction scheduler 701 with 3 dispatch ports 704. Up to 3 instructions can be scheduled and dispatched out of program order using those ports to execute on the 3 execution units 702. They write back their results using write back ports 705 to the reorder buffer 703 each cycle. Then up to 3 instructions can retire from the instruction reorder/retirement buffer 703 so that their destinations registers can non-speculatively and permanently update the architecture state.

In contrast to the typical implementation of out of order hardware of FIG. 7, the current invention describes a dynamic scheduling out of order architecture that scales much better using the concepts of the instruction matrix/bucket and the group level dependency check and instruction group dispatch and execution as shown in FIG. 8.a. An instruction matrix buffer and scheduler 801 stores those instruction matrices/blocks/buckets.

In this example, the instruction bucket 806 is determined to satisfy its dependency sources and thus it is ready to be dispatched and so is bucket 808 and 809. Those buckets can execute in single cycle if the underlying hardware allows that or they can be staged in execution units 802 over multiple consecutive cycles in a pipelined or non pipelined fashion. After their execution is finished their results are written into instruction matrix retirement register file 803. They are written as a group of registers representing the bucket using the write back ports 805. Those bucket destination registers stay in the bucket retirement buffer until the bucket as a whole can update the architecture state in the original sequential order of the program.

One possible implementation for this concept is described in with 3 components:

1—The front end

2—The Scheduler and Execution

3—The Back end retirement The front end includes: Speculative Thread Bucket-pointers, Bucket Sources and destinations lists. The scheduler and execution buckets include a bucket dispatch selector and the virtual register match and read, including the possibility of a register hierarchy and a register cache. The Back end is where executed buckets are logged and exception ordering is enforced before retirement. The register hierarchy/cache also serves as an intermediate storage for the executed bucket results until they are non-speculative and can update the architecture state similar to 803 shown in FIG. 8.a. The following discloses one possible implementation of the front end, the dispatch stage and the backend where executed buckets are logged. Those are shown in FIG. 8. b

The process starts by fetching a new thread Matrix/bucket/block, and then the new thread bucket is assigned into a vacant bucket slot in the bucket buffer. Each of the thread allocation pointers in the thread allocation pointer array 852 composes an interval of buckets that the thread is allowed physically to place its blocks/buckets of instruction in it. Each of those threads keeps allocating buckets into the bucket buffer array inside its corresponding interval of contiguous space in round-robin fashion. The buckets/blocks inside each thread space get assigned a new number 852 that is incremented each time a new bucket/block gets assigned. For each valid source in the bucket 850, The valid sources for each bucket has a valid read bit “Rv” indicating that this source is needed for the instructions inside this bucket. By the same convention, each destination register that is to be written back by instructions in this bucket has a valid bit “Wv” set in the bucket and it has a field in a destination inheritance vector 853. When a new bucket is to be fetched into the bucket buffer it inherits the destination inheritance vector from the previous allocated bucket pointed at by the thread bucket allocation pointer 852. The inheritance vector is copied from the previously allocated bucket and then it overwrites those valid destination fields that correspond to the registers which will be updated by those bucket instructions. The valid destinations will be labeled with the current bucket number, while the invalid destinations are copied from the corresponding inheritance vector inside the bucket. Then the thread bucket pointer is updated for the new fetched bucket by incrementing its pointer (it wraps around within its interval).

In the bucket dispatch and execute stage, whenever a bucket is executed without any exception handling, then the bucket execution flag (containing the bucket number) 854 is set and broadcasted through out the bucket buffer and is latched/monitored within each bucket that has a source with that bucket number as a source. It is also possible to pass other related information along the bucket number, such as information about virtual registers locations. When all the execution flags of the sources buckets are set within a bucket, then that bucket ready bit 855 is set and the bucket is ready to be dispatched and executed. When the bucket executes without any exception and it is ready to update the architecture state in the sequential order of the program, then it retires the bucket and the retirement thread pointer 857 is incremented to the next bucket in the array. The retired bucket location can be assigned to a new bucket.

Those closely related threads can all coexist inside the Matrix/bucket/block buffer; each thread will occupy an interval of consecutive buckets that belongs to that thread. The allocation pointer of that thread moves inside this interval of buckets in a round robin fashion fetching new instruction buckets and allocating them inside the thread interval in the described round robin fashion. With such interval sectioning, the whole bucket buffer is divided dynamically with different or equal interval lengths of buckets.

The concept of inheritance vector is introduced here for the instruction bucket as well as for the thread. Each instruction matrix/block/bucket writes into particular registers among the architectural registers. Each new bucket upon allocation stage updates this inheritance vector writing the thread and bucket number of its own into this vector leaving the fields for the registers that it does not write into un-updated. This bucket inheritance vector B_iv 856 is forwarded from each bucket to the next one in program order. In FIG. 8.b each matrix writes its own number into the architecture destination registers if the instructions in that matrix write into those registers, otherwise it inherits the value from the B_iv of the previous bucket in that thread.

This concept scales from a bucket buffer managing a small number of closely coupled threads into hardware circuits that manage multiple bucket buffers and threads as shown by way of implementation example in FIG. 9. Those circuits that can be expanded to process larger numbers of threads that might have less close interaction are describe as a global front end that process a thread header 902 but does not need to process the actual instructions within the thread to enforce the dependency check across those distant threads. The header of the thread and the sub headers of its buckets contain only information about the architecture registers that those threads and buckets writes into (destination registers of those instructions) no need in those headers to include actual instructions or sources of those instructions. Actually it is enough to list those destination registers or a bit vector where each individual bit is set for each register that is a destination for an instruction. The header does not need to be physically placed as a header for the instructions; it can be any formatted packet or compact representation or of the destination registers of the instructions within the threads, which may or may not be stored with the rest of the instructions information.

This global front-end fetches only the headers of the threads/blocks in program order and generates dynamic thread and/or bucket inheritance vectors 901 (Tiv and/or Biv). Each time a new thread is allocated, those inheritance vectors are forwarded by keeping the old fields that the current thread bucket will not write to or update as shown 903. Those inheritance vectors are distributed to a large number of engines/cores or processors 904 each of which might include a local front-end and a fetch unit (which will fetch and store the actual instructions produce the dependency vector for each bucket) and a local matrix/block/bucket buffer with local register files 905. The local front-ends then fetch the actual instructions and use the information from the inheritance vectors obtained from the global front end to fill the dependency information for the instruction sources of the instructions that are brought into those engines for execution. FIG. 9 illustrates a global front-end implementation and the way it disseminates the inheritance vectors to the different engines 904 using only concise information about the instructions (which is just the registers that those instructions write into). Other information that is of help to place in the header is that information about a change in the control path within or across the threads. A global branch predictor can be used to predict the flow of control across those threads. So such headers can include the branching destinations and offsets. In addition to the branch predictor to determine control flow, the hardware/compiler can decide to dispatch independent threads across the 2 control paths of a branch. In such case it will later merge the execution of those 2 paths using the inheritance vector as will be shown in FIG. 11. FIG. 9 also shows the forwarding process when a header of a new thread is fetched by the global front, thread 2 (906) for example will update the corresponding inheritance vector 901 that is forwarded to it resulting in vector 910 where registers 1, 2, 3, 4, 6, 0 and 7 are updated with T2 labels. Note that in 910 register 5 was not written by T2 buckets and thus its label was inherited from a previous inheritance vector.

One interesting observation is that the register files allow cross communication among the cores/engines. An early request (to reduce the access latency) of the registers that are needed from cross engines can be placed as soon as the instruction buckets of the thread are fetched and allocated in the local bucket buffer at that time the source dependency information is populated such that cross engine threads references can be issued at that time probably long before the actual instructions are dispatched for execution. In any case, the instruction will not be dispatched until the cross referenced source is forwarded and arrived. This cross referenced source can be stored in the local multi-threaded register file or register cache. Although this cross referenced source can be stored in a buffer similar to the load store buffer (it can reuse the load store buffer physical storage and dependency check mechanisms but as a register load instead of memory load). Many topologies can be used to connect the register files across the engines/cores, which may be a ring topology or cross bar topology or mesh routed interconnect.

The following discussion can illustrate how register file segmentation can be used inside an engine and also across engines. When the bucket is dispatched, its sources are sent to both (simultaneously or sequentially) to the register file and the register cache. If the register file is physically unified and has direct support for threading, then the operand is read directly from the corresponding thread register section. If the register file is a virtual register, including a physically segmented register file that uses tags, then a tag match has to be done as a part of the virtual register read. If the tag matches, then the read happens from the segmented register file.

FIG. 9.b shows the overall virtual register file and register cache. It also shows the segmentation of the execution and the low level register files. A SIMD or MIMD instruction accesses the respective SIMD/MIMD register data segment in each section while a VLIW instruction accesses a different register in each segment independently. In threading mode, each section independently has separate instructions that access registers independently and can access cross segment registers in a unified view. More ways of how the threads can uses the register files hierarchies are shown in FIGS. 1-5

To allow for the option of keeping the instruction scheduling as composed by compiler auto parallelization or VLIW or SMID/MIMD composition without allowing the hardware to rearrange the section buckets independently, a locking mechanism is employed through the use of a bit or a flag that locks the 4 buckets together as a super bucket. If this bit or flag is set, then all the buckets within the super bucket (in this case 4 buckets) will execute in parallel within the same cycle. If the flag is not set, then those buckets are not locked to execute together and can be independently executed at various times.

Increased parallelism that results from threading or out-of-order execution or VLIW architectures puts huge pressure on the limited bandwidth register file. Usually register files are designed as a unified resource to allow access to all registers. Segmented register files have been designed before, but they have required handling of cross reads/writes at the architecture/software level, which prevents them from being utilized as a unified set of resources and adds overhead to the cross reads/writes.

Disclosed is register architecture that supports software threads, hardware generated threads, VLIW execution, SIMD & MIMD execution as well as emulation of out-of-order super-scalar execution. Although it is physically segmented, it looks as a unified architecture resource. This segmented register is part of the virtual register file which might include a register hierarchy and a register cache as well as mechanisms to store and check register tags. The tag access can be eliminated if we use a location based scheme that takes advantage of the dependency inheritance vector. The scheme works such that when the executed bucket number is broadcasted during dispatch stage all the sources of subsequent instructions perform a CAM (content addressable match) which compares their sources buckets with the just dispatched/executed bucket to set the ready flag for that source. Here the physical location of where that bucket executed can also be propagated along with the register number so that any ambiguity is resolved. For example in FIG. 9.c there are 4 register file segments, each contains 16 registers. For example upon dispatching a bucket # x to section 2 the bucket number x is broadcasted to the bucket buffer and also the segment #2 is broadcasted with it such that all sources that have a dependency on bucket x will record that it wrote all its registers in segment 2. When time comes to dispatch those instructions, they know that they need to read their register from segment 2 and not any other segment, even though the same register number exists in the other segments. This also applies to the register cache to avoid using tags. We can extend this concept to the global front end where in addition to the thread information the inheritance vector can specify in which engine the instruction bucket writing to this register was allocated.

The following is a description of an implementation of a unified dynamic execution architecture capable of issuing SIMD/MIMD, VLIW, ULIB bucket instructions as well as Dynamic and Static threading. The architecture also supports emulating a super scalar out-of-order implementation without the explicit support of out-of-order components. The invention may also encompass a physically segmented, architecturally unified register file and a possible register cache hierarchy.

The disclosed techniques allow for both software initiated threads (static threads) as well as hardware generated threads (dynamic threads) to be executed using one unified method and implementation. As mentioned earlier, fine grain parallelism is hard to identify at the software static optimization level and thus the dynamic threading is a way that the hardware can generate this fine level parallelism by assigning dynamic thread contexts to software buckets, such as function calls, methods subroutines/procedures, independent object codes or parallel loops. This is accomplished with the disclosed implementation and method by reserving a few of the threads and their bit identification fields to the dynamic threads. For example, in the above implementation, the hardware dynamic threads can be assigned a subset thread group out of the “m” threads available. The hardware can use those allocated thread reservations to dynamically generate and/or issue hardware threads. For example, upon a function call or subroutine call (as indicated by an assembly “Call” instruction), the hardware can assign a new hardware thread to such call and eventually can claim back the thread reservation after the return function. The same can be said about loops where a hardware thread can be generated at the entrance of a loop (as indicated by an assembly “Loop” instruction) and can be reclaimed after the loop reaches its end instruction. Other instructions can also be used for possible hardware threading opportunities that map directly to software threading-applicable events, such as Object oriented method executions or object associated codes or any high level or object oriented programming thread opportunities. In all cases the synchronization of those threads can be resolved through register/bucket cross referencing and control flags, which can be tracked and resolved by the earlier described mechanisms. FIG. 10 illustrates how the hardware (or the compiler or run time system) can use the dynamic hardware threads to overlap execution of instructions in different regions around and within a loop body.

Again the thread header encapsulates the destination registers of each bucket within the loop body 1004 as well as the code outside the loop body. The hardware or the compiler in this case is allocating a thread T1 to the code before the loop body, and as an example only one thread to the loop body T2 (multiple threads can be assigned to the loop body by splitting the loop into multiple iterations to the extent where each loop iteration can be assigned to a thread, the amount of loop threading is a dynamic decision that can be decided at run time or based on compiler analysis) while the code after the loop is assigned to thread T3.

Note that the inheritance vector 1005 generated by the buckets of the loop body feeding back to the loop body itself T2 is slightly different from that inheritance vector 1005 forwarded to the thread outside the loop body T3. This is because T3 needs the last copy of the registers iterated on by the loop, this last copy is indicated in the inheritance vector 1002 by n. When the last iteration of the loop is reached then all the buckets in that last iteration carries a flag n that is set as a part of the bucket number (i.e., most significant bit).

T3 registers that depend on the loop body of T2 will depend on this last iteration n of the iterative loop of T2. This is what will also be recorded in the forwarded inheritance vector for T3. The assumption here is that T2 does not have any control path internally that changes the update of the loop registers to be at a different iteration instead of the last iteration, predication can be used to resolve such control path if it exists internal to the loop body. The identifier n can be carried and forwarded as a part of the inheritance vector as in 1003. It basically refers to the buckets that compose the last iteration of the loop. In addition, these dynamic threads can be assigned to branching code (the code that follows a branch or a control change).

The technique can be used to issue 2 threads, one along each of the 2 possibilities of a branch. In such a case, one of the threads commits and the other is thrown away once the branch is resolved architecturally. To take care of the case where the 2 different control paths affect different registers, the inheritance forwarding vector will specify the flag condition F that the inheritance will embed into its bucket number field 1101. In this case, each source in the dependent buckets on this control path will specify the condition flag within the inheritance vector 1102 for those source registers that are impacted by the variable path of control. The flag will be broadcasted with the bucket number that executes/resolves that flag to all dependent buckets during the CAM dispatch match. This is illustrated in FIG. 11. The flag means that the distant buckets do not yet know (till the flag condition is executed and resolved) which thread will forward a particular register value they need. The threads along the 2 possible paths of the branch continue executing along their paths till the flag is resolved and one of them (along the miss predicted path) will be destroyed. But during the execution along those 2 paths, many other buckets following the branch have been fetched and allocated and their inheritance vector forwarded. Those need the flag so that they can substitute it (while waiting for their dependency to resolve) with the right bucket number from the thread of control along the correct path of execution. Note that we also can take advantage of the thread and bucket header to find out the needed information.

Another innovation is the inclusion of a flag field within each architecture register, such that each architecture or physical register has a flag field as part of the visible state. This allows for a simple predication mechanism for conditional execution of an instruction and the ability to easily create delay slots for branch instructions. For example, in a loop, the test instruction that tests the loop end condition has to be preceding the branch instruction with no other flag modifying instructions in between. Using the register flag field, and by specifying that this branch depends on the flag of a particular register (the destination of the test instruction in this example), the test condition could be placed at the beginning of the loop while the actual branch can be at the end of the loop. Therefore, by the time the branch instruction is at the front end of the machine, the test instruction has already been executed and the branch can execute at the front end stage rather than at the execution stage, thus removing bubbles. Those register flags also facilitate simple instruction predication or thread predication, where instructions or instructions in a particular thread can be predicated based upon the result of a particular instruction that does not need to be preceding it immediately in the execution sequence. This is illustrated in FIG. 11.b. The test instruction 1150 is executed ahead of where the branch is. Based on its result it will fetch the right path of the program instructions and keep them aside until the branch instruction 1151 is allocated at the front end and then it feeds those instructions in the pipeline. It is possible also for this architecture to predicate the instructions after the branch 1152 and execute them before the branch and uses a conditional move after executing the branch. It is also possible to issue 2 threads alongside the 2 possible control paths of execution as illustrated in FIG. 11.b.

Moreover as shown in FIG. 11.b, the test instruction 1150 can execute speculatively even if its sources are speculative or predicted by the hardware or the compiler, but it writes into a speculative flag F2, when the actual test instruction that precedes the branch 1151 executes it writes into the flag F1, at that point the 2 flags are compared and if they match the speculative thread of execution that started with the test instruction 1150 then that thread continues as being on the correct control path, while the other thread stops fetching instructions using the inheritance merging mechanism shown in FIG. 11.a. In the case the flags do not match, then the other thread continues fetching and the thread of the early test stops. This allows for thread speculation and fast recovery from miss speculation (no latency penalty for early speculation of branches).

The handling of memory cross referencing by threads is another key element in the thread auto generation and auto synchronization. Those references are made using memory accesses by loads and stores.

In FIG. 12 we show a comprehensive scheme and implementation of the synchronization scheme among threads and/or among loads and stores in general. The scheme describes a preferred method for synchronization and disambiguation of memory references across load/store architectures and/or across memory references and/or threads' memory accesses. In FIG. 12, we show multiple segments of register files (address and or data registers), execution units, address calculation units, level 1 caches and/or load store buffers and level 2 caches and address register interconnects 1200 and address calculation unit interconnects 1201. Those segmented elements could be constructed within one core/processor by segmenting and distributing its centralized resources into several engines or they can be constructed from elements of different cores/processors in multi-core/multi-processor configurations. One of those segments 1211 is shown in the figure as segment number 1; the segments can be scaled to a large number (in general to N segments as shown in the figure).

This mechanism also serves also as a coherency scheme for the memory architecture among those engines/cores/processors. This scheme starts by an address request from one of the address calculation units in one segment/core/processor. For example, assume the address is requested by segment 1 (1211). It can obtain and calculate its address using address registers that belong to its own segment and or from registers across other segments using the address interconnect bus 1200. After calculating the address it creates the reference address of either 32-bit address or 64-bit address that is used to access caches and memory. This address is usually fragmented into a tag field and a set and line fields. This particular segment/engine/core will store the address into its load store buffer and/or L1 and/or L2 address arrays 1202, at the same time it will create a compressed version of the tag (with smaller number of bits than the original tag field of the address) by using a compression technique. More the different segments/engines/cores/processors will use the set field or a subset of the set field as an index to identify which segment/core/processor the address is maintained in. This indexing of the segments by the address set field bits ensures exclusiveness of ownership of the address in a particular segment/core/engine even though the memory data that corresponds to that address can live in another or multiple other segments/engines/cores/processors. Even though the address CAM/tag arrays 1202/1206 are shown in each segment to be coupled with the data arrays 1207, they might be only coupled in physical proximity of placement and layout or even by the fact that both belongs to a particular engine/core/processor, but there is no relation between addresses kept in the address arrays and the data in the data arrays inside one segment. After the compressed address tag is formed, the set's field bits are used to identify the particular address CAM array 1202 that the request will be addressed to. Let us assume that it turned out that those set field bits identified segment/engine/core/processor N as the one that owns that address scope, then the compressed tag is sent to that segment/engine/core/processor (segment N) L1 CAM and/or corresponding L2 CAM arrays that will then perform Content address match (CAM) between the incoming compressed tag and the compressed tags it stores in its array. Since this is a compressed tag the CAM array width is minimal and thus we can afford to build a Cam array that has a similar number of entries to the data array (usually CAM arrays are very expensive and power hungry). After the CAM match is done it can result in hit or a miss or multiple hits (a good compression technique should reduce the number of multiple hits) Then in a case of hit/multiple hits the Loc array (location array) 1203 corresponding to the CAM hit entry in segment N is read to identify the location of the memory data that belongs to this address CAM hit. This location is sent back to the requesting address calculation unit in requesting segment (in this example segment 1). That address calculation unit request buffer 1204 sends the full address to the Address/Tag array of that location 1206 using the address bus of the interconnect 1205. Then a tag look up and compare is performed to ensure a confirmed/unique hit. Then if the hit is confirmed the data is returned using the data bus of interconnect 1205. If a miss happened in either the CAM or the complete Tag array, a request to the main memory is put on behalf of the requesting segment. It is possible also to cut the latency more and send the full address to the segment that owns that address scope (using the set field bits as an index) as described before, and at that segment the compressed tag is formed and accesses the CAM array first while the full address is held there till the result of the CAM is checked and the location array 1203 is read to identify the entry numbers in the tag array 1206 that was a hit in the compressed tag 1202. Then the full compare is done on the full address using comparators as opposed to the CAM. The implementation of the CAM array 1202 does not really need to be performing a CAM, since this compare is to be done on few bits that are obtained from the full tag and compressed, the CAM array can be implemented as a direct indexed memory array (RAM) or register file, for example if the compressed tag is formed as an 8-bit word then the whole CAM array of each segment can be constructed as a 256 entry RAM array, when the 8-bit compressed tag comes it directly gets decoded to read one of the 256 entries of the Location array 1202 (in reality for such case of 8-bit compressed tag, the CAM array does not need to exist as a physical array), it actually only need to be used as the decoder for the location array 1203.

Next we will describe a scheme that defines memory latency reduction by issuing memory loads a head of time without increasing register pressure by defining transient storage variables called “Temp” and “Chain”. Temp is used only once to allow an instruction to refer to a location in memory and prefetch it to a particular location in the cache buffer, This is different from typical schemes of data prefetching to the cache because with Temps and chains there is a direct 1 to 1 mapping between the Temp prefetched value and its consuming instruction; similar to what a register assignment might achieve, On the contrary, in typical cache prefetching schemes the memory data is prefetched into an address location in the cache, the consuming instruction can only reference this prefetched data by its memory address. Which Is not known to the scheduler of the consuming instruction, thus the consumer instruction has no control over finding the data when it executes. In the case of the new Temp and chain schemes described here, the memory data is brought into the cache buffer (loaded into the cache) and is assigned a name “e.g. Temp0”, the consuming instruction of this loaded data can now refer explicitly the Temp 0 name and expect to find it in the Temp 0 location with absolute guarantee when it executes, Because the Temp number is indicated as a source of dependency in the consuming instruction, thus the scheduler will not issue that instruction until the Temp is valid (the data was actually loaded from higher level caches or memory) similar to what happens when a memory value is loaded into a register. This has an extra benefit beside precise prefetching (1 to 1 mapping) and precise scheduling of the consuming instruction which is allowing for variable latency distributed caches as shown in FIG. 12.

To prevent destruction of the Temp and Chain before their consumer instructions freed them, the compiler will ensure that it will not reassign that register until its consumer instruction consumes it.

There are a few differences between a register assignment and Temp assignment; the Temp is used to bring the needed data into a transient location in the Cache buffer that get automatically de-allocated upon the consumption of that value by the consuming instruction (the instruction that references that transient location), this will insure that the live range of this temp is short and thus it is used very efficiently. One way the Temp can be assigned in a program is through using a label that goes with the load address calculation instruction (or with the address calculation instruction bucket) i.e:

Label Temp0: Load @ Address (R5, R2, offset) . . . . . .

R10←R17, Temp0

The labels for the temps that are to be used within a code segment or function must be allocated before they are used. So if the compiler is intending to use 10 Temp locations for prefetching its data, it should use an allocate instruction/routine that allocates those Temp locations in the cache/buffer. After each instruction consumes its Temp, the Temp location will be free. The hardware can reallocate those Temp locations/labels for another function through a context switch; this is possible by making the cache/buffer that stores the Temp data allocated with thread ID tagging. The hardware will assign a new thread ID and new Temp locations upon encountering the Label allocate instruction of the new function. If there is no space to occupy for a new thread in the cache/buffer, then during the execution of the allocate instruction/routine, the temp locations that are not free (because their instructions did not consume them yet) will get saved/stored in memory with the rest of the old thread context that is being switched. Those Temp data need to be restored and loaded back when that old thread context is brought back to continue execution. This will take care of unexpected executions of context switch (e.g. upon a call to an exception handler or a system call).

Chains are similar to Temps with 2 differences: the chain is a sequence of locations as oppose to just one, secondly the whole chain is labeled with one label no matter how many elements “locations” it has. Chain needs to be allocated using an allocation instruction/routine similar to the temp. Similarly, upon executing this allocate instruction if there is no new thread space for that chain in the cache/buffer that can be assigned to the new thread chain then that particular chain elements are checked to see which ones are already freed (because their consuming instructions used them) the ones that are not freed will be saved to memory and the new thread chain can use that space. Chains allows to create a 1 to 1 mapping between a list of prefetching/loading instructions and the consuming instructions to allow obtaining an effect similar to having a register with a variable name number e.g. R(i). This is useful in accessing arrays inside loops where the chain can start prefetching the values inside the loop long before the consuming instruction in the loop need them, But without creating a register pressure. A cache structure or cache buffer can be used to store those Temp and chain elements. FIG. 13 shows an implementation for such concept in an out of order execution style. We show here again an instruction scheduler/block buffer 1304 and the forwarding inheritance vector. Once a chain is allocated it has its write counter 1300 in the inheritance vector reset to zero. With each new assignment through a load to the chain, the write counter is incremented and thus the destination element in each instruction that writes to the chain element will get this new incremented number e.g after 3 assignments to load three memory locations into the cache buffer, the counter value will be three 1301. Inside the loop code and for each iteration of the loop, with every chain load instruction, the write counter will continue incrementing; those unrolled dynamic instructions that load into the chain will have those incremented numbers. On the consuming instruction side there is a read counter 1303 that also keep incrementing upon encountering each consuming instruction that read from a chain element. E.g the first instruction to reference chain 0 to read its first element will increment the read counter from 0 to 1, then the next consuming instruction to read from the chain will increment the counter to 2 and thus it knows that it need to read from chain 0 2^(nd) element. This scheme of write counters and read counters will ensure implicit synchronization between the loads of the chain elements and their consuming instructions without really relying on the actual address of the load. This will have a similar impact of having a variable register index e.g., R(i).

FIG. 13.b shows how the entries (e.g., Temp 16 shown as 1350) in the Cache or buffer 1351 can be dynamically assigned to the Temps and chains depending on the allocating instruction 1352 inserted by the compiler/hardware. In the figure chain A is assigned to hardware chains 0, 1, 2, 3 (each having 4 locations in the buffer) by combining their storage 1353, thus chain A is allocated 16 entries in total). Shown in the figure how also the storage of chains and Temps are overlaid on top of each other, thus the storage can be assigned to one or the other at the same time.

FIG. 14 describes a mechanism to provide out of order execution to calculating the memory addresses using address registers but without excessive storage space needed to rename those address registers. The scheme takes advantage of the fact the address registers are usually updated by incrementing or decrementing them 1400, while the full memory address can be constructed by adding and scaling multiple of these address registers to form the full address (e.g. adding a base register to the index register and using a scaling factor and an offset). The scheme use the hardware scheduler/instruction bucket buffer 1401 and the inheritance vector 1402 to store the increment/decrement counter 1403, (i.e. every time an address register is incremented or decremented the inheritance vector notes the instruction/bucket that made that update and keeps track of the counter 1403 of the increment/decrement events inside the scheduler/bucket buffer. There will be only one actual physical address register per each address register name, (so no multiple physical registers that refers to the same register name as used in typical renaming schemes). To load other values or perform updates other than incrementing or decrementing the address register then the regular data registers must be used (since they are renamed and can store multiple versions of a register name and values). A copy of the data register will be sent to the one address register upon executing such involved update instruction and then thereafter, the address register can be incremented or decremented as described using the inheritance vector to keep track of the updates.

FIG. 15 extends the load usage to allow speculative prefetching/loading of the data passing earlier store instructions 1500 (those stores that precede loads in the program order),

The scheme uses a qualifier in the Temp assigning instruction 1503 (the prefetch/load instruction). This temp assigning/prefetch instruction brings the data into the transient location in the cache it does not perform any ordering checks on the address (finding out id the address of the load matches that of a store that did not execute yet, This order check is done to prevent the load from bringing data from memory that is not yet updated by a store that precedes the load in sequential execution). The ordering check will be performed when the consuming instruction 1504 executes, at that point if the ordering check finds that the address of the prefetch is loading from the same address of the preceding store the consuming instruction 1504 will use a bypass mechanism to get the store value instead of the Temp value. The bypass mechanism can be implemented along the order checking process performed as part of the execution phase of the consuming instruction 1504 by inspecting the store buffer for a matching address and if one is found for an earlier store that was executed after the temp instruction loaded data from memory then the value of that store will be bypassed to the consuming instruction instead of the temp value. The consuming instruction itself can be executed speculatively ahead of the store instruction by using the same thread control speculation that we discussed in FIG. 11 by issuing and conditionally executing a prefetch/load thread on the ordering check that can be made explicitly or implicitly upon the execution of the preceding store 1500.

We showed throughout this invention description by way of example the implementation schemes using Temp, chains and instruction buckets but the schemes that we described can be applied to loads or single instructions in general.

Also the synchronization and coherency schemes that we illustrated does not only apply to distributed caches or separate address register files, they can also be used with centralized caches among different processors and they can also be used partially or by trivial modifications to the schemes.

An embodiment of the present invention relates to a computer storage product with a computer-readable medium having computer code thereon for performing various computer-implemented operations. The media and computer code may be those specially designed and constructed for the purposes of the present invention, or they may be of the kind well known and available to those having skill in the computer software arts. Examples of computer-readable media include, but are not limited to: magnetic media such as hard disks, floppy disks, and magnetic tape; optical media such as CD-ROMs, DVDs and holographic devices; magneto-optical media; and hardware devices that are specially configured to store and execute program code, such as application-specific integrated circuits (“ASICs”), programmable logic devices (“PLDs”) and ROM and RAM devices. Examples of computer code include machine code, such as produced by a compiler, and files containing higher-level code that are executed by a computer using an interpreter. For example, an embodiment of the invention may be implemented using Java, C++, or other object-oriented programming language and development tools. Another embodiment of the invention may be implemented in hardwired circuitry in place of, or in combination with, machine-executable software instructions.

The foregoing description, for purposes of explanation, used specific nomenclature to provide a thorough understanding of the invention. However, it will be apparent to one skilled in the art that specific details are not required in order to practice the invention. Thus, the foregoing descriptions of specific embodiments of the invention are presented for purposes of illustration and description. They are not intended to be exhaustive or to limit the invention to the precise forms disclosed; obviously, many modifications and variations are possible in view of the above teachings. The embodiments were chosen and described in order to best explain the principles of the invention and its practical applications, they thereby enable others skilled in the art to best utilize the invention and various embodiments with various modifications as are suited to the particular use contemplated. It is intended that the following claims and their equivalents define the scope of the invention. 

1. A multiple thread architecture, comprising: a plurality of thread registers storing a corresponding plurality of thread contexts; and inter-thread communication circuitry between the plurality of thread registers to support thread communication and synchronization.
 2. A multiple thread architecture, comprising: a set of registers; a set of execution units; circuitry to coordinate the set of registers and set of execution units to support instruction level parallelism and the execution of software threads and hardware generated threads.
 3. The multiple thread architecture of claim 2 wherein the circuitry processes a flag bit to lock the execution of a group of instructions.
 4. The multiple thread architecture of claim 3 wherein the group of instructions is selected from SIMD, MIMD, VLIW, and ULIB formats.
 5. The multiple thread architecture of claim 3 wherein the group of instructions are used as a virtual reference for dependency tracking and resolution at a group level.
 6. A multiple thread architecture, comprising: a set of register files configurable to include context identification without designating a separate register file for each context.
 7. A multiple thread architecture, comprising: an execution bucket; and a register file hierarchy configured to support high bandwidth small capacity register files adjacent the execution bucket and lower bandwidth and larger capacity register files removed from the execution bucket.
 8. A context switch architecture, comprising: context switch circuitry to support the capture of current state information; and a context storage mechanism configured to simultaneously store a portion of the current state information and a portion of previous state information, so as to incrementally switch context.
 9. The context switch architecture of claim 8 wherein the context storage mechanism is a Last In First Out (LIFO) circuit.
 10. A multiple thread architecture, comprising: a plurality of thread registers storing a corresponding plurality of thread contexts; and inter-thread communication circuitry between the plurality of thread registers to support thread communication and synchronization. 